//
//  U9FaithManager.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/8/8.
//  Copyright © 2017年 UUU9. All rights reserved.
//

#import "U9FaithManager.h"
#import "U9FaithModel.h"
#import "U9FaithOutput.h"
#import "U9FaithListModel.h"

@implementation U9FaithManager

#pragma mark 获取热门战队

+ (void)getFaithListWithGid:(NSString *)gid andCompletionHandle:(void(^)(U9FaithListModel *faith, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?cid=%@",Api_URL,kGetFaithList,gid]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    U9FaithListModel *model = [U9FaithListModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


+ (void)getFaithByUserID:(NSString *)userid andSessionid:(NSString *)sessionid andCompletionHandle:(void(^)(U9FaithOutput *faith, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,sessionid];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetUserFaith]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9FaithOutput *model = [U9FaithOutput mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}



+ (void)setFaithWithUID:(NSString *)userid andFaithid:(NSString *)faithid andSessionid:(NSString *)sessionid andCompletionHandle:(void(^)(U9FaithOutput *faith, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&mid=%@&sessionid=%@",userid,faithid,sessionid];
    [self EncryptPOST:[NSString stringWithFormat:@"%@%@",Api_URL,kSetUserFaith]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9FaithOutput *model = [U9FaithOutput mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


/*
 #pragma mark ----------------------------------------  信仰
 #pragma mark 获取热门战队
 - (void)getHotTeam:(NSString *)gid andBlock:(RequestFinishBlock)block{
 [self.manager GET:[NSString stringWithFormat:@"%@%@",Api_URL,kGetHotTeam]
 parameters:@{@"gid":gid}
 progress:nil
 success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
 @try {
 id dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
 if ([dict[@"error_code"] longLongValue] == 0) {
 [_plist storageToPlist:dict andFileName:@"HotTeam"];
 } else {
 dict = [_plist readFromPlist:@"HotTeam"];
 }
 if (block) {
 block(dict);
 }
 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isOnline"];
 }
 @finally {
 
 }
 }
 failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
 [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"isOnline"];
 NSMutableDictionary *dict = [_plist readFromPlist:@"HotTeam"];
 if (block) {
 block(dict);
 }
 }];
 }
 
 
 #pragma mark 设置信仰
 - (void)setFaith:(NSString *)userid andFaithid:(NSString *)faithid andSessionid:(NSString *)sessionid andBlock:(RequestFinishBlock)block{
 NSString *param = [NSString stringWithFormat:@"userid=%@&mid=%@&sessionid=%@",userid,faithid,sessionid];
 [self.manager POST:[NSString stringWithFormat:@"%@%@",Api_URL,kSetUserFaith]
 parameters:@{@"_secdata":_paramaters,@"param":[self base64Encoding:param]}
 progress:nil
 success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
 @try {
 NSData *resData = [[NSData alloc] initWithData:[[self base64Decoding:responseObject] dataUsingEncoding:NSUTF8StringEncoding]];
 id dict = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingAllowFragments error:nil];
 if ([dict[@"error_code"] longLongValue] == 0) {
 [_plist storageToPlist:dict andFileName:@"HotTeam"];
 } else {
 dict = [_plist readFromPlist:@"HotTeam"];
 }
 if (block) {
 block(dict);
 }
 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
 [userDefaults setBool:YES forKey:@"isOnline"];
 }
 @finally {
 
 }
 }
 failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
 [userDefaults setBool:false forKey:@"isOnline"];
 NSMutableDictionary *dict = [_plist readFromPlist:@"HotTeam"];
 if (block) {
 block(dict);
 }
 }];
 
 }
 
 #pragma mark 获取信仰
 - (void)getFaith:(NSString *)userid andSessionid:(NSString *)sessionid andBlock:(RequestFinishBlock)block{
 NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,sessionid];
 [self.manager POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetUserFaith]
 parameters:@{@"_secdata":_paramaters,@"param":[self base64Encoding:param]}
 progress:nil
 success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
 @try {
 NSData *resData = [[NSData alloc] initWithData:[[self base64Decoding:responseObject] dataUsingEncoding:NSUTF8StringEncoding]];
 id dict = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingAllowFragments error:nil];
 if (block) {
 block(dict);
 }
 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
 [userDefaults setBool:YES forKey:@"isOnline"];
 }
 @finally {
 
 }
 }
 failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
 [userDefaults setBool:false forKey:@"isOnline"];
 }];
 }
 
 */
@end
